package com.zk5_education.service_edu.controller;


import com.zk5_education.R;
import com.zk5_education.service_edu.entity.EduChapter;
import com.zk5_education.service_edu.entity.chapter.OneChapter;
import com.zk5_education.service_edu.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import  java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-08-08
 */
@RestController
@RequestMapping("/service_edu/edu_chapter")
@CrossOrigin
public class EduChapterController {


    @Autowired
    EduChapterService eduChapterService;

    @GetMapping("/getAllChapter/{courseId}")
    public R getAllChapter(@PathVariable String courseId){

        List<OneChapter> list=eduChapterService.getallChapter(courseId);
        return R.success().data("list",list);
    }
    //添加章节

    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){

         eduChapterService.save(eduChapter);
        return R.success();
    }
    //查询章节
    @GetMapping("/selectchapter/{chapterid}")
    public R selectChapter(@PathVariable String chapterid){
        EduChapter chapter = eduChapterService.getById(chapterid);

        return R.success().data("chapter",chapter);
    }

    //修改章节
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return R.success();
    }

    //删除章节
    @DeleteMapping("deleteChapter/{Chapterid}")
    public R DeleteChapter(@PathVariable String Chapterid){
        boolean flag= eduChapterService.deleteChapter(Chapterid);

        return flag?R.success():R.error();
    }
}

